#include <stdio.h>
#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif
  #include "lua.h"
  #include "lualib.h"
  #include "lauxlib.h"
#ifdef __cplusplus
}
#endif

#if defined(_WIN32) || defined(_WIN64)
#pragma comment(lib, "lua5.1.lib")
#endif

int main (void) {
  char buff[256];
  int error;
  
  lua_State *L = luaL_newstate(); /* opens Lua */
  luaL_openlibs(L);               /* opens standard librarys */

  while (fgets(buff, sizeof(buff), stdin) != NULL) {
    error = luaL_loadbuffer(L, buff, strlen(buff), "line") ||
            lua_pcall(L, 0, 0, 0);
    if (error) {
      fprintf(stderr, "%s", lua_tostring(L, -1));
      lua_pop(L, 1);             /* pop error message from the stack */
    }
  }

  lua_close(L);
  return 0;
}

